//文件下载
import { message } from "ant-design-vue";
export default {
  exportFile(blobData, fileName) {
    // 检查 blobData 是否有效
    if (!blobData || blobData.size === 0) {
      message.error('导出失败：文件数据无效。请联系管理员');
      return;
    }
    try {
      const blob = new Blob([blobData], { 
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      });
      const downloadElement = document.createElement('a');
      const href = window.URL.createObjectURL(blob);
      downloadElement.href = href;
      downloadElement.download = fileName;
      document.body.appendChild(downloadElement);
      downloadElement.click();
      // 清理
      document.body.removeChild(downloadElement);
      window.URL.revokeObjectURL(href);
    } catch (error) {
      console.error('文件下载失败:', error);
      message.error('导出失败，请联系管理员');
    }
  }
}